package Components;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import smash_tris.Room;

public class StatisticButton extends JButton {
	
	private Room room;
	private Image background;
	private String player[] = new String[2];
	
	
	public StatisticButton(Room room, ImageIcon back) {
		//super();
		player[0] = "";
		player[1] = "";
		this.background = back.getImage();
		this.room = room;
		int i = 0;
    	System.out.println("while i< this.room.getPLayers...");
		while (i< this.room.getPlayers().size()){
			System.out.println("times");
    		this.player[i] = room.getPlayers().get(i).getNick();
    		
    		i++;
    	}
		System.out.println("end }");
		this.setSize(251, 62);
		this.setVisible(true);
		this.repaint();
	}
	
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        g.drawImage(background, 15, 5, null);
        
        g.drawString(room.getName(),27,22);
        g.setColor(Color.WHITE);
        g.drawString(this.player[0] + " : " +this.player[1] ,125, 47);
        
        g.drawString(room.getNumPlay()+"/"+room.getMaxSize(),232,27);
    }
    
    /**
     * Metoda zwraca referencję do pokoju reprezentowanego 
     * przez przycisk.
     * @return
     */
    public Room getRoom() {
		return room;
	}
    
    
    /**
     * Metoda aktualizuje informacje zawarte na buttonie
     */
    public void resetButtonInfo() {
		int i = 0;
    	while (i< this.room.getPlayers().size()){
    		this.player[i] = room.getPlayers().get(i).getNick();
    		i++;
    	}
    	
	}
    
    
 /*  
    @Override
    public String getText() {
    	room.getName();
    	return super.getText();
    }
*/
}
